package com.bifrii.bo;

import java.util.List;
import com.bifrii.dao.IRouteDAO;
import com.bifrii.dao.JDBCRouteDAO;
import com.bifrii.dao.UIDGenerator;
import com.bifrii.transferObjects.Route;

public class RouteManager {
	
		private static IRouteDAO route;
		private static RouteManager rm;
		
		public static synchronized RouteManager getInstance(){
			if(rm == null)
				rm = new RouteManager();
			return rm;
		}
		
		private RouteManager(){
			route = new JDBCRouteDAO();
		}
		
		//Este metodo sirve para saber si ya existe una ruta en el mismo lugar y en la misma fecha
		
		public boolean testRoute(String place, String date){ 
			
			boolean ret = true;
			List<Route> routes = route.selectAll();
			for(Route r: routes){
				if(r.getPlace().equals(place) && r.getDate().equals(date))
					ret=false;
			}
			return ret;
		}
		
		public Route newRoute(Route r){
			r.setOid(UIDGenerator.getInstance().getKey());
			r.setIdEvent(EventManager.getInstance().getLastId());
			route.insert(r); 	
			return r;
		}
		
		public Route getRoute(Integer idRoute){
			return route.select(idRoute);
		} 
		public void deleteRoute(Integer idRoute){
			route.delete(idRoute);
		}
		
		public List<Route> selectAllRoutes(Integer idEvent){
			return route.selectAll(idEvent);
		}
	
}
